package com.itheima;

import org.testng.annotations.Test;

import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

/**
 * @ProjectName: ybxy6
 * @Titile: TreeMap
 * @Author: 86183
 * @Description: TODO
 */
public class TreeMapDemo {
    public static void main(String[] args) {
        test1();
        test2();
    }
    @Test//单元测试
    public static void test1() {
        // 创建集合对象
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("张三", "北京");
        treeMap.put("李四", "上海");
        treeMap.put("王五", "广州");
        treeMap.put("赵六", "深圳");
        treeMap.put("小七", "广州");
        treeMap.put("小八", "广州");
        treeMap.put("小九", "广州");
        treeMap.put("小十", "广州");
        treeMap.forEach((k, v) -> System.out.println(k + ":" + v));
    }
    public static void test2( ) {
        // 创建集合对象
        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>(){
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
    });
        treeMap.put(new Student("马林", 18), "北京");
        treeMap.put(new Student("坎特雷拉", 19), "上海");
        treeMap.put(new Student("长离", 20), "广州");
        treeMap.put(new Student("吟霖", 22), "广州");
        treeMap.put(new Student("公孙离", 21), "深圳");

        treeMap.forEach((k, v) -> System.out.println(k + ":" + v));
        HashMap<String, String> map = new HashMap<>();
        map.put("张三", "北京");
    }
}
